package com.wjh.rules.assembler.operator.chain.unit;

import com.wjh.rules.assembler.operator.chain.AbstractOperator;
import com.wjh.rules.common.conts.OperatorConts;
import com.wjh.rules.common.conts.ScriptOpetorConts;

public class RangeOperator extends AbstractOperator {
    public RangeOperator(String type) {
        super(type);
    }

    /**
     * column range 1,2
     *
     * @param message
     * @return
     * @throws Exception
     */
    @Override
    protected String format(String message) throws Exception {

        message = this.templateSimpleParam(message);
        String[] arr = message.split(this.operatorType);
        String left = arr[0].trim();
        String right = arr[1].trim();
        //获取区间数字
        String[] rights = right.split(",");
        StringBuffer sb = new StringBuffer();
        sb.append(left)
                .append(ScriptOpetorConts.SCRIPT_BLANK)
                .append(OperatorConts.GTE)
                .append(ScriptOpetorConts.SCRIPT_BLANK)
                .append(rights[0])
                .append(ScriptOpetorConts.SCRIPT_BLANK)
                .append(ScriptOpetorConts.AND)
                .append(left)
                .append(ScriptOpetorConts.SCRIPT_BLANK)
                .append(OperatorConts.LTE)
                .append(ScriptOpetorConts.SCRIPT_BLANK)
                .append(rights[1])
                .append(ScriptOpetorConts.SCRIPT_BLANK);
        return sb.toString();
    }
}
